package net.imwork.amorgemini.service;

import net.imwork.amorgemini.entity.Book;
import net.imwork.amorgemini.repository.mysql.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lvbr on 2017-07-2617:58.
 */
@Service
public class BookService implements BaseService<Book, Integer> {

    @Autowired
    BookRepository bookRepository;

    @Override
    @Cacheable(value = "bookList")
    public List<Book> findAll() {
        return bookRepository.findAll();
    }

    @Override
    public Book save(Book entity) {
        return bookRepository.save(entity);
    }

    @Override
    public void delete(Integer id) {
        bookRepository.delete(id);
    }

    @Override
    public Book update(Book entity) {
        return bookRepository.save(entity);
    }

    @Override
    public Book getOne(Integer id) {
        return bookRepository.getOne(id);
    }

    public void exceptionTest() throws Exception {
//        throw new MyException(ExceptionDict.UNKNOW_ERROR);
//        throw new MyException(ExceptionDict.UNKNOW_ERROR);
        int i = 1 / 0;
    }
}
